﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApplication4.Entity;

namespace WebApplication4.Domain
{
    public class DbIntializerHelper
    {
        public static void Intialzer()
        {
            using(var db = new Admin1000DbContext())
            {
               var dbExist = db.Database.EnsureCreated();
                var tempBrand = db.Brands.Any();

                if (!tempBrand)
                {
                    var brand1 = new Brand
                    {
                        BrandName = "Microsoft",
                        Description = "比尔.盖茨的公司"
                    };

                    var brand2 = new Brand
                    {
                        BrandName = "Facebook",
                        Description = "扎克伯格的公司"
                    };
                    db.Brands.Add(brand1);
                    db.Brands.Add(brand2);
                    db.SaveChanges();
                    db.Products.AddRange(new Product[]
                    {
                    new Product
                    {
                        ProductName = "Windows",
                        ShortDesc = "操作系统",
                        FullDesc = "微软研发的操作系统",
                        BrandId = brand1.Id
                    },

                    new Product
                    {
                        ProductName = "Facebook",
                        ShortDesc = "社交软件",
                        FullDesc = "美国社交服务网站",
                        BrandId = brand2.Id
                    },

                    });

                    db.SaveChanges();
                }


                
            }
        }
    }
}
